/*
 * Carlos René Michel Morales
 * 
 * Clase para el manejo de los tweets del API de twitter
 */

package piticli.twitter;

import java.text.ParseException;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.*;
/**
 *
 * @author Rene
 */
public class Tweet {

     private Long id;
     private String text;
     private String source;
     private boolean truncated;
     private Long in_reply_to_status_id;
     private Long in_reply_to_user_id;
     private String in_reply_to_screen_name;
     private User user;
     private String created_at;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public String getSource() {
        return source;
    }

    public void setSource(String source) {
        this.source = source;
    }

    public boolean isTruncated() {
        return truncated;
    }

    public void setTruncated(boolean truncated) {
        this.truncated = truncated;
    }

    public Long getIn_reply_to_status_id() {
        return in_reply_to_status_id;
    }

    public void setIn_reply_to_status_id(Long in_reply_to_status_id) {
        this.in_reply_to_status_id = in_reply_to_status_id;
    }

    public Long getIn_reply_to_user_id() {
        return in_reply_to_user_id;
    }

    public void setIn_reply_to_user_id(Long in_reply_to_user_id) {
        this.in_reply_to_user_id = in_reply_to_user_id;
    }

    public String getIn_reply_to_screen_name() {
        return in_reply_to_screen_name;
    }

    public void setIn_reply_to_screen_name(String in_reply_to_screen_name) {
        this.in_reply_to_screen_name = in_reply_to_screen_name;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }
    
    public String getCreated_at() {
        return created_at;
    }

    public void setCreated_at(String created_at) {
        this.created_at = created_at;
    }
    
    public static Tweet getTweetFromJSONObject(JSONObject obj) throws JSONException{
        Tweet retTweet = new Tweet();
        
        retTweet.source = obj.get("source").toString();
        retTweet.id = obj.getLong("id");
        retTweet.text = obj.get("text").toString();
        retTweet.truncated = obj.getBoolean("truncated");
        retTweet.in_reply_to_screen_name = obj.getString("in_reply_to_screen_name").toString();
        retTweet.created_at = obj.getString("created_at").toString();
        
        
        //retTweet.in_reply_to_status_id = obj.getLong("in_reply_to_status_id");
        //retTweet.in_reply_to_user_id = obj.getLong("in_reply_to_user_id");
        
        try {
            retTweet.user = User.getUserFromJSONObject(obj.getJSONObject("user"));
        } catch (ParseException ex) {
            Logger.getLogger(Tweet.class.getName()).log(Level.SEVERE, null, ex);
            System.out.println("No se puede obtener el objeto User");
        }
        
        return retTweet;
    }

    
     
}
